-
Notifications
You must be signed in to change notification settings - Fork 14.3k
MC,AsmPrinter: Report redefinition error instead of crashing in more cases #145460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MaskRay
merged 1 commit into
main
from
users/MaskRay/spr/mcasmprinter-report-redefinition-error-instead-of-crashing-in-more-cases
Jun 24, 2025
Merged
MC,AsmPrinter: Report redefinition error instead of crashing in more cases #145460
MaskRay
merged 1 commit into
main
from
users/MaskRay/spr/mcasmprinter-report-redefinition-error-instead-of-crashing-in-more-cases
Jun 24, 2025
+12
−10
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-mc @llvm/pr-subscribers-backend-x86 Author: Fangrui Song (MaskRay) Changes
Full diff: https://github.com/llvm/llvm-project/pull/145460.diff 5 Files Affected:
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 403963f33b65c..1bfa551d71966 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1081,13 +1081,6 @@ void AsmPrinter::emitFunctionHeader() {
/// function. This can be overridden by targets as required to do custom stuff.
void AsmPrinter::emitFunctionEntryLabel() {
CurrentFnSym->redefineIfPossible();
-
- // The function label could have already been emitted if two symbols end up
- // conflicting due to asm renaming. Detect this and emit an error.
- if (CurrentFnSym->isVariable())
- report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
- "' is a protected alias");
-
OutStreamer->emitLabel(CurrentFnSym);
if (TM.getTargetTriple().isOSBinFormatELF()) {
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index c43619d712172..c6dbc625642d4 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -569,7 +569,8 @@ void MCAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
// FIXME: Fix CodeGen/AArch64/arm64ec-varargs.ll. emitLabel is followed by
// setVariableValue, leading to an assertion failure if setOffset(0) is
// called.
- if (getContext().getObjectFileType() != MCContext::IsCOFF)
+ if (!Symbol->isVariable() &&
+ getContext().getObjectFileType() != MCContext::IsCOFF)
Symbol->setOffset(0);
Symbol->print(OS, MAI);
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 1bb2143ed6ab2..e959a242dfcf5 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -225,6 +225,10 @@ void MCObjectStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
void MCObjectStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
MCStreamer::emitLabel(Symbol, Loc);
+ // If Symbol is a non-redefiniable variable, emitLabel has reported an error.
+ // Bail out.
+ if (Symbol->isVariable())
+ return;
getAssembler().registerSymbol(*Symbol);
diff --git a/llvm/test/CodeGen/X86/equiv_with_fndef.ll b/llvm/test/CodeGen/X86/equiv_with_fndef.ll
index 3da0aa60250c2..a858ec2bf4537 100644
--- a/llvm/test/CodeGen/X86/equiv_with_fndef.ll
+++ b/llvm/test/CodeGen/X86/equiv_with_fndef.ll
@@ -1,4 +1,4 @@
-; RUN: not --crash llc < %s 2>&1 | FileCheck %s
+; RUN: not llc < %s 2>&1 | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@@ -7,4 +7,4 @@ module asm ".equiv pselect, __pselect"
define void @pselect() {
ret void
}
-; CHECK: 'pselect' is a protected alias
+; CHECK: <unknown>:0: error: symbol 'pselect' is already defined
diff --git a/llvm/test/MC/AsmParser/redef-err.s b/llvm/test/MC/AsmParser/redef-err.s
index e191d01003f41..ff0b1cc221549 100644
--- a/llvm/test/MC/AsmParser/redef-err.s
+++ b/llvm/test/MC/AsmParser/redef-err.s
@@ -12,3 +12,7 @@ l:
.equiv a, undef
# CHECK: [[#@LINE-1]]:11: error: redefinition of 'a'
+
+.equiv b, undef
+b:
+# CHECK: [[#@LINE-1]]:1: error: symbol 'b' is already defined
|
arsenm
approved these changes
Jun 24, 2025
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Jun 24, 2025
…ng in more cases * Fix the crash for `.equiv b, undef; b:` (.equiv equates a symbol to an expression and reports an error if the symbol was already defined). * Remove redundant isVariable check from emitFunctionEntryLabel Pull Request: llvm/llvm-project#145460
DrSergei
pushed a commit
to DrSergei/llvm-project
that referenced
this pull request
Jun 24, 2025
…cases * Fix the crash for `.equiv b, undef; b:` (.equiv equates a symbol to an expression and reports an error if the symbol was already defined). * Remove redundant isVariable check from emitFunctionEntryLabel Pull Request: llvm#145460
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
.equiv b, undef; b:
(.equiv equates a symbol to an expression and reports an error if the symbol was already defined).